<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="default" @click="handleExport()">
          <Icon icon="ant-design:download-outlined" /> {{ t('导出') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ djno: record.djno })">
          {{ record.djno }}
        </a>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsAsdTlAsdTmTlList',
  });
</script>
<script lang="ts" setup>
  import { defineComponent } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { useGlobSetting } from '/@/hooks/setting';
  import { downloadByUrl } from '/@/utils/file/download';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { u8SumListData } from '/@/api/bas/u8Sum';
  import { FormProps } from '/@/components/Form';
  import { propTypes } from '/@/utils/propTypes';

  const { t } = useI18n('asd.tl.asdTmTl');
  const props = defineProps({
    cwhcode: propTypes.string,
  });
  console.log('cwhcode',props.cwhcode);
  const getTitle = {
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: router.currentRoute.value.meta.title || t('退料申请管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('物料编码'),
        field: 'cinvcode',
        component: 'Input',
      },
      {
        label: t('物料代码'),
        field: 'cinvaddcode',
        component: 'Input',
      },
      {
        label: t('物料名称'),
        field: 'cinvname',
        component: 'Input',
      },
      {
        label: t('仓库'),
        field: 'cwhcode',
        component: 'Input',
      },
      {
        label: t('区域'),
        field: 'areacode',
        component: 'Input',
      },
      {
        label: t('货位'),
        field: 'cposname',
        component: 'Input',
      },
      {
        label: t('批次'),
        field: 'cbatch',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('物料编码'),
      dataIndex: 'cinvcode',
      key: 'a.cinvcode',
      sorter: true,
      width: 170,
      align: 'left',
    },
    {
      title: t('物料代码'),
      dataIndex: 'cinvaddcode',
      key: 'a.cinvaddcode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('物料名称'),
      dataIndex: 'cinvname',
      key: 'a.cinvname',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('区域'),
      dataIndex: 'areacode',
      key: 'a.areacode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('货位编码'),
      dataIndex: 'cposcode',
      key: 'a.cposcode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('货位'),
      dataIndex: 'cposname',
      key: 'a.cposname',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('仓库'),
      dataIndex: 'cwhcode',
      key: 'a.cwhcode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('批次'),
      dataIndex: 'cbatch',
      key: 'a.cbatch',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('数量'),
      dataIndex: 'iqty',
      key: 'a.iqty',
      sorter: true,
      width: 130,
      align: 'right',
    },
  ];

  const [registerTable] = useTable({
    api: u8SumListData,
    beforeFetch: (params) => {
      if (props.cwhcode) {
        params.cwhcode = props.cwhcode;
      }
      return params;
    },
    columns: tableColumns,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  async function handleExport() {
    const { ctxAdminPath } = useGlobSetting();
    downloadByUrl({
      url: ctxAdminPath + '/wh/u8/u8InvpositionSum/exportData',
      target: '_self',
    });
  }
</script>
